package com.controller;


import com.entity.Interview;
import com.service.InterviewService;
import com.utils.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 * 面试表 前端控制器
 * </p>
 *
 * @author Damon
 * @since 2021-04-26
 */
@RestController
@CrossOrigin
@RequestMapping("/interview")
@Api(value = "InterviewController", tags = {"个人投递简历接口"})
public class InterviewController {
    // 注入数据模型
    @Autowired
    private InterviewService InterviewService;
    public int i=3;
    /** 投递简历到某职位 */
    @PostMapping("/sendResume") // Post方法
    @ApiOperation(value = "投递简历到某职位", notes = "投递简历到某职位", httpMethod = "POST")
    public DataResult sendResume(
            @ApiParam(name = "userInfo", value = "投递简历信息对象", required = true)
            @RequestBody Interview interview)
    {

        // 更改对象属性
        interview.setStatus(0);  // 状态 0-已投递 1-企业已查看 2-企业邀请 3-企业拒绝 4-面试 5-结束

        Date date = new Date();
        interview.setCreatedTime(date);
        if(date!=null){
            i=i+1;
            System.out.println(i);
            interview.setId(Integer.toString(i));
        }

        // System.out.println(resumePosition);
        // 设置添加成功的返回标志
        boolean flag = InterviewService.save(interview);
        if(flag) {
            // 成功返回数据
            return DataResult.finished().message("简历投递成功！");
        } else {
            // 失败返回数据
            return DataResult.failed().message("简历投递失败！");
        }
    }
}

